package priv.pront.code.national.acwing.dp.bags;

import java.util.Scanner;
/*fixme 为何采用倒序遍历*/
public class A2_01背包问题 {

    static int n, V;
    static int[] w , v ;
    static int[] dp;
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        V = scanner.nextInt();
        w = new int[n + 1];
        v = new int[n + 1];
        dp = new int[V + 1];

        for(int i = 1; i <= n; i++){
            v[i] = scanner.nextInt();
            w[i] = scanner.nextInt();
        }
        for(int i = 1; i <= n; i++){
            for(int j = V; j >= v[i]; j--){
                dp[j] = Math.max(dp[j], dp[j - v[i]] + w[i]);
            }
        }
        System.out.println(dp[V]);
    }
}
